/*
 * Copyright (c) 2017-2020, Lindenis Tech. Ltd.
 * All rights reserved.
 *
 * File:
 *
 * Description:
 *
 * Author:
 *      xiaoshujun@lindeni.com
 *
 * Create Date:
 *      2020/10/20
 *
 * History:
 *
 */

#ifndef __FF_DEMUX_H__
#define __FF_DEMUX_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "osal_types.h"
#include "lindcomponent.h"

typedef struct _ffdemux_config_t
{
    comm_msg_cb cb;
    void * user;
    char url[256];

    /*
     * playback range between the time 'start_us' and 'end_us'
     *  >0 : valid
     * <=0 : do not care
     */
    int64_t start_us;
    int64_t end_us;

    /*
     * probe file use less time if set it '1'
     */
    int i_open_ultrafast;
} ffdemux_config_t;

typedef enum _demux_status_e
{
    DEMUX_STATUS_ERROR                  = -1,
    DEMUX_STATUS_IDLE                   = 0x0,
    DEMUX_STATUS_PREPARE                = 0x1,
    DEMUX_STATUS_START                  = 0x2,
    DEMUX_STATUS_PAUSE                  = 0x4,
    DEMUX_STATUS_STOP                   = 0x8,

    DEMUX_STATUS_SEEK_NONE              = 0x1000,
    DEMUX_STATUS_SEEK_VIDEO             = 0x2000,
    DEMUX_STATUS_SEEK_AUDIO             = 0x4000,
    DEMUX_STATUS_SEEK_START             = DEMUX_STATUS_SEEK_VIDEO | DEMUX_STATUS_SEEK_AUDIO,
    DEMUX_STATUS_SEEK_END               = 0x8000,
} demux_status_e;

typedef enum _demux_msg_e
{
    DEMUX_MSG_NONE                      = -1,
    DEMUX_MSG_EOF                       = 0,
} demux_msg_e;

typedef enum _demux_ioctrl_e
{
    DEMUX_IOCTRL_NONE                   = -1,
    DEMUX_IOCTRL_GET_DURATION           = 0,
    DEMUX_IOCTRL_GET_PRIVPARAM_AS,
    DEMUX_IOCTRL_GET_PRIVPARAM_VS,
    DEMUX_IOCTRL_GET_STATUS,

    DEMUX_IOCTRL_DISABLE_VIDEO_STREAM   = 100,
    DEMUX_IOCTRL_DISABLE_AUDIO_STREAM,
    DEMUX_IOCTRL_SELECT_VIDEO_STREAM,
    DEMUX_IOCTRL_SELECT_AUDIO_STREAM,
    DEMUX_IOCTRL_SET_SPEED_1X,
} demux_ioctrl_e;

_handle_t ffdemux_create();
void ffdemux_destroy(_handle_t h_demux);
int  ffdemux_init(_handle_t h_demux, ffdemux_config_t * p_config);
int  ffdemux_deinit(_handle_t h_demux);
int  ffdemux_start(_handle_t h_demux);
int  ffdemux_stop(_handle_t h_demux);
int  ffdemux_pause(_handle_t h_demux);
int  ffdemux_resume(_handle_t h_demux);
int  ffdemux_ioctrl(_handle_t h_demux, int type, void * ext1, void * ext2);
void ffdemux_flush(_handle_t h_demux);
int  ffdemux_read_audio(_handle_t h_demux, av_frame_t * p_frame);
int  ffdemux_read_video(_handle_t h_demux, av_frame_t * p_frame);
int  ffdemux_read_audio2(_handle_t h_demux, av_frame2_t ** p_frame);
int  ffdemux_return_audio2(_handle_t h_demux, av_frame2_t * p_frame);
int  ffdemux_read_video2(_handle_t h_demux, av_frame2_t ** p_frame);
int  ffdemux_return_video2(_handle_t h_demux, av_frame2_t * p_frame);

#ifdef __cplusplus
}
#endif

#endif  // __FF_DEMUX_H__

